package org.cloud.ext.mq.consumer;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.cloud.ext.mq.common.MessageTypeEnum;
import org.cloud.ext.mq.config.RabbitMqConfiguration;
import org.cloud.ext.mq.factory.MessageFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author xukk
 * @date 2020/3/10
 */
@Component
@Slf4j
public class FanoutConsumer {

    /**
     * 通知公告
     * @param message
     */
    @RabbitListener(queues = RabbitMqConfiguration.FANOUT_NOTICE1)
    public void consumerNotice1(String message) {
        log.warn("【接收听到通知公告】{}", message);
        MessageFactory.getByType(MessageTypeEnum.NOTICE).handle(JSON.parseObject(message));
    }

    /**
     * 意见反馈
     * @param message
     */
    @RabbitListener(queues = RabbitMqConfiguration.FANOUT_FEEDBACK1)
    public void consumerFeedback1(String message) {
        log.warn("【接收听到意见反馈】{}", message);
        MessageFactory.getByType(MessageTypeEnum.NOTICE).handle(JSON.parseObject(message));
    }

    /**
     * 报表
     * @param message
     */
    @RabbitListener(queues = RabbitMqConfiguration.FANOUT_REPORT1)
    public void consumerReport1(String message) {
        log.warn("【接收听到报表】{}", message);
        MessageFactory.getByType(MessageTypeEnum.NOTICE).handle(JSON.parseObject(message));
    }

    /**
     * 待办
     * @param message
     */
    @RabbitListener(queues = RabbitMqConfiguration.FANOUT_GTASKS1)
    public void consumerGtasks1(String message) {
        log.warn("【接收听到待办】{}", message);
        MessageFactory.getByType(MessageTypeEnum.NOTICE).handle(JSON.parseObject(message));
    }

    /**
     * 默认
     * @param message
     */
    @RabbitListener(queues = RabbitMqConfiguration.FANOUT_DEFAULT1)
    public void consumerDefault1(String message) {
        log.warn("【接收听到默认事件】{}", message);
        MessageFactory.getByType(MessageTypeEnum.DEFAULT).handle(JSON.parseObject(message));
    }
}
